import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
 state: () => ({
  token:localStorage.getItem('token') || '',
  UserInfo: JSON.parse(localStorage.getItem('UserInfo') || 'null')} ),
  roleLogos: JSON.parse(localStorage.getItem('roleLogos') || '[]'),
  actions: {
    setToken(t,u,roles = []) {
      this.token = t
      this.UserInfo=u
       this.roleLogos = roles
      localStorage.setItem('token', t);
      localStorage.setItem('UserInfo', JSON.stringify(u))   // ← 序列化
      localStorage.setItem('roleLogos', JSON.stringify(roles))

    },
  }
})

